/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package android.sql;

/**
 *
 * @author payo
 */
public class Table 
{
    private int columnas;
    private Object[][] tabla;

    public void addRow(String... arreglo)
    {
        if(arreglo.length == columnas){
            tabla = resizeTable();
            int lastRow = tabla.length-1;
            for(int x=0;x<arreglo.length;x++)
                tabla[lastRow][x] = arreglo[x];
        }
        else throw new UnsupportedOperationException("Invalid Row");
    }
    
    public Table(int columnas)
    {
        this.columnas = columnas;
        tabla = new Object[0][columnas];
    }
    
    public int getColumnCount()
    {
        return columnas;
    }

    public int getRowCount()
    {
        return tabla.length;
    }

    public String getValueAt(int row, int col)
    {
        return String.valueOf(tabla[row][col]);
    }
    
    public Object[] getRow(int row)
    {
        Object[] ob = new Object[columnas];
        for(int x=0;x<columnas;x++)
            ob[x] = tabla[row][x];
        return ob;
    }

    private Object[][] resizeTable() {
        int rows = tabla.length;
        Object[][] newTable = new Object[rows+1][columnas];
        for(int a=0;a<rows;a++)
            System.arraycopy(tabla[a], 0, newTable[a], 0, columnas);        
        return newTable;
    }
}
